layui.define([ 'form', 'laydate', 'table','doctoralSubsidyApi'], function(exports) {
    var form = layui.form;
    var doctoralSubsidyApi = layui.doctoralSubsidyApi;
    var index = layui.index;
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                 form.on('submit(form)', function(){
                     /**
                      * 获取身份证,银行卡材料信息,进站批文,学位证书,市经费资助证明文件
                      */

                     var isEmpty = Common.fileRequire("#IdfileDataList");
                     var banknumber = Common.fileRequire("#banknumberDataList");
                     var entranceApproval= Common.fileRequire("#entranceApprovalDataList");
                     var certificate= Common.fileRequire("#certificateDataList");
                     var supportCertificate= Common.fileRequire("#supportCertificateDataList");
                     if(isEmpty){
                         Common.alert("身份证件附件必须上传");
                     }else if(banknumber){
                         Common.alert("银行卡材料信息附件必须上传");
                     }else if(entranceApproval){
                         Common.alert("进站批文附件必须上传");
                     }else  if(certificate){
                         Common.alert("学位证书附件必须上传");
                     } else if(supportCertificate){
                         Common.alert("市经费资助证明附件必须上传");
                     }else {
                         doctoralSubsidyApi.addDoctoralSubsidy($('#addForm'), function () {
                             parent.window.dataReload();
                             Common.info("添加成功");
                             Lib.closeFrame();
                         });
                     }
                });
            });

            $("#addButton-PandD").click(function(){
                /**
                 * 获取身份证,进站批文,学位证书,市经费资助证明文件
                 */

                var isEmpty = Common.fileRequire("#IdfileDataList");
                var banknumber = Common.fileRequire("#banknumberDataList");
                var entranceApproval= Common.fileRequire("#entranceApprovalDataList");
                var certificate= Common.fileRequire("#certificateDataList");
                var supportCertificate= Common.fileRequire("#supportCertificateDataList");

                if(isEmpty){
                    Common.alert("身份证件附件必须上传");
                }else if(banknumber){
                    Common.alert("银行卡材料信息附件必须上传");
                }else if(entranceApproval){
                    Common.alert("进站批文附件必须上传");
                }else  if(certificate){
                    Common.alert("学位证书附件必须上传");
                } else if(supportCertificate){
                    Common.alert("市经费资助证明附件必须上传");
                }else {
                    form.on('submit(form)', function () {
                        Common.openConfirm("确认申报?", function () {
                            doctoralSubsidyApi.savedeclaration($('#addForm'), function () {
                                parent.window.dataReload();
                                Common.info("保存并申报成功");
                                Lib.closeFrame();
                            });
                        }, null);
                    });
                }
            });


            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    			
    }
    exports('add',view);
});